package com.kedou.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.kedou.app.R;
import com.kedou.domain.User;

public class GridAdapter extends BaseAdapter {
	private Context mContext;
	private ArrayList<User> mUsers;

	public GridAdapter(Context mContext, ArrayList<User> mUsers) {
		this.mContext = mContext;
		this.mUsers = mUsers;
	}

	public void addList(ArrayList<User> users) {
		this.mUsers.addAll(users);
		this.notifyDataSetChanged();
	}

	public ArrayList<User> getList() {
		return this.mUsers;
	}

	@Override
	public int getCount() {
		return mUsers.size();
	}

	@Override
	public Object getItem(int position) {
		return mUsers.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		User user = mUsers.get(position);
		LayoutInflater inflater = LayoutInflater.from(mContext);
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.investorlist_item, null);
			holder.mImgHead = (ImageView) convertView
					.findViewById(R.id.image_investor_head);
			holder.mTvName = (TextView) convertView
					.findViewById(R.id.tv_investor_head);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		// 头像 待处理
		holder.mTvName.setText(user.getRealName());
		return convertView;
	}

	public class ViewHolder {
		public ImageView mImgHead;
		public TextView mTvName;
	}
}
